package com.xmy.cultivate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmy.cultivate.entity.RatePay;
import com.xmy.cultivate.mapper.RatePayMapper;
import com.xmy.cultivate.service.IRatePayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hpiggy
 * @since 2023-06-06
 */
@Service
public class RatePayServiceImpl extends ServiceImpl<RatePayMapper, RatePay> implements IRatePayService {

    @Autowired
    RatePayMapper ratePayMapper;

    @Override
    public boolean updateStatusForOrderId(Long orderId, Integer status) {
        QueryWrapper<RatePay> ratePayQueryWrapper = new QueryWrapper<>();
        ratePayQueryWrapper.eq("order_id", orderId);
        List<RatePay> ratePayList = ratePayMapper.selectList(ratePayQueryWrapper);
        for (RatePay ratePay : ratePayList) {
            ratePay.setStatus(status);
            ratePayMapper.updateById(ratePay);
        }
        return true;
    }

    @Override
    public List<Long> getIdsByUseCourseCount(Long studentId, Long subjectsId, Integer yearPart, Integer quarterNum) {
        return ratePayMapper.getIdsByUseCourseCount(studentId, subjectsId, yearPart, quarterNum);
    }
}
